package com.mm.fam.web.netty;

import com.mm.fam.web.netty.vo.Decoder;
import com.mm.fam.web.netty.vo.Encoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
//        socketChannel.pipeline().addLast("decoder", new Decode());
//        socketChannel.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
//        socketChannel.pipeline().addLast(new NettyServerHandler());


//        socketChannel.pipeline().addLast("frameDecoder", new DelimiterBasedFrameDecoder(80, Delimiters.lineDelimiter()));
//        socketChannel.pipeline().addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
//        // 编码器
//        socketChannel.pipeline().addLast("encoder", new XLServerEncoder());
//        socketChannel.pipeline().addLast("handler", new XLServerHandler());

        // 添加自定义协议的编解码工具
        socketChannel.pipeline().addLast(new Encoder());
        socketChannel.pipeline().addLast(new Decoder());
        // 处理网络IO
        socketChannel.pipeline().addLast(new NettyServerHandler());
    }
}
